package com.dwxt.community.admin.controller;

import com.dwxt.common.base.BaseResult;
import com.dwxt.community.admin.service.CustomerServiceAdmin;
import com.dwxt.community.entity.CustomerProblem;
import com.dwxt.community.entity.vo.CustomerProblemVO;
import com.dwxt.community.service.CustomerService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/cms/customer")
public class CustomerControllerAdmin {

    @Autowired
    private CustomerServiceAdmin customerServiceAdmin;

    @Autowired
    private CustomerService customerService;

    @RequestMapping("/page")
    public BaseResult page(Integer pageNum, Integer pageSize, String username) {
        PageHelper.startPage(pageNum, pageSize);
        List<CustomerProblemVO> customerProblemVOList = customerServiceAdmin.selectCustomerList(username);
        PageInfo<CustomerProblemVO> pageInfo = new PageInfo<>(customerProblemVOList);
        return BaseResult.ok(pageInfo);
    }

    @RequestMapping("/selectDetail")
    private BaseResult selectDetail(String id) {
        List<CustomerProblem> customerProblems = customerService.selectProblemDetail(id);
        return BaseResult.ok(customerProblems);
    }

    @RequestMapping("/commitReply")
    public BaseResult commitReply(Integer id, String reply) {
        customerServiceAdmin.commitReply(id, reply);
        return BaseResult.ok();
    }
}
